package cn.itzzx.lagou.minicat.mapper;

import cn.itzzx.lagou.minicat.servlet.HttpServlet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Martin
 * @since 1.0
 */
public class Mapper {

    /**
     * 可以存在多个 hosts
     */
    public volatile List<MappedHost> hosts = new ArrayList<>();

    /**
     * 设置默认的 hostname
     */
    private String defaultHostName = "localhost";

    public String getDefaultHostName() {
        return defaultHostName;
    }

    public void setDefaultHostName(String defaultHostName) {
        this.defaultHostName = defaultHostName;
    }

    public class MappedHost {
        //hostname
        private String name;

        //绝对路径
        private String appBase;
        //<Context path="/sids/" docBase="/Users/martin/Downloads/abc" />
        //key path
        private Map<String,MappedContext> contextMap = new HashMap<>();


        public MappedHost(String name, String appBase) {
            this.name = name;
            this.appBase = appBase;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAppBase() {
            return appBase;
        }

        public void setAppBase(String appBase) {
            this.appBase = appBase;
        }

        public Map<String, MappedContext> getContextMap() {
            return contextMap;
        }

        public void setContextMap(Map<String, MappedContext> contextMap) {
            this.contextMap = contextMap;
        }
    }

    public  class MappedContext {
        // 项目名称
        private String name;

        // key uri
        private Map<String, HttpServlet> wrapper = new HashMap<>();

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Map<String, HttpServlet> getWrapper() {
            return wrapper;
        }

        public void setWrapper(Map<String, HttpServlet> wrapper) {
            this.wrapper = wrapper;
        }
    }

    public void addHost(MappedHost mappedHost){
        hosts.add(mappedHost);
    }

}
